package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.activity.douluodalu.data.DouLuoDaLuTeamData;
import com.yanqu.road.entity.activity.douluodalu.data.DouLuoDaLuUserData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroup;
import com.yanqu.road.logic.cross.CrossActivityTeamRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.manager.activity.ActivityTeamRankMgr;
import com.yanqu.road.server.manager.douluodalu.CrossDouLouDaLuActivity;
import com.yanqu.road.server.manager.douluodalu.CrossDouLuoDaLuMgr;
import com.yanqu.road.server.manager.union.activitygroup.Cross2UnionActivityGroupMgr;

import java.util.Map;

public class DouLuoDaLuCrossRank extends BaseCrossRank {

    public DouLuoDaLuCrossRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {

//        AutoSendRewardProto.CrossUserRankMsg.Builder msg = getCrossNormalActivityUserRankMsg();
        //个人积分榜去YRank那边了
//        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
//        int teamConditionType = eGamePlayerEventType.DouLuoDaLuPhaseTwoTeamScoreCrossRank.getValue();
//        Map<Integer, UnionActivityGroup> groupMap = Cross2UnionActivityGroupMgr.getGroupMap(activityId);
//        if (groupMap != null) {
//            for (UnionActivityGroup activityGroup : groupMap.values()) {
//                CrossActivityTeamRankListModel teamRankListModel = ActivityTeamRankMgr.getCrossActivityTeamRankListModel(activityId, teamConditionType, activityGroup.getGroupId());
//                if (teamRankListModel != null) {
//                    CrossDouLouDaLuActivity activity = CrossDouLuoDaLuMgr.getActivityOrNull(activityId, activityGroup.getGroupId());
//                    if (activity != null) {
//                        int i = 1;
//                        for (CrossActivityProto.TeamRankTempMsg rankTempMsg : teamRankListModel.getRankListMsg().getRankListList()) {
//                            DouLuoDaLuTeamData teamData = activity.getAllTeamMap().get(rankTempMsg.getTeamId());
//                            if (teamData == null) {
//                                continue;
//                            }
//                            for (Map.Entry<Long, Long> longEntry : teamData.getMemberList().entrySet()) {
//                                long uid = longEntry.getKey();
//                                DouLuoDaLuUserData user = activity.getAllUserMap().get(uid);
//                                if (user != null) {
//                                    addUserRankData(msg, teamConditionType, uid, i);
//                                }
//                            }
//                            i++;
//                        }
//                    } else {
//                        CrossDouLuoDaLuMgr.getLogger().info("DouLuoDaLuCrossRank activity : {} groupId {} not in memory", activityId, activityGroup.getGroupId());
//                    }
//                }
//            }
//        }

//        return msg;
        return null;
    }


    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        return null;
    }

    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg(int groupId) {
        int teamConditionType = eGamePlayerEventType.DouLuoDaLuPhaseTwoTeamScoreCrossRank.getValue();
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        CrossActivityTeamRankListModel teamRankListModel = ActivityTeamRankMgr.getCrossActivityTeamRankListModel(activityId, teamConditionType, groupId);
        if (teamRankListModel != null) {
            CrossDouLouDaLuActivity activity = CrossDouLuoDaLuMgr.getActivityOrNull(activityId, groupId);
            if (activity != null) {
                int i = 1;
                for (CrossActivityProto.TeamRankTempMsg rankTempMsg : teamRankListModel.getRankListMsg().getRankListList()) {
                    DouLuoDaLuTeamData teamData = activity.getAllTeamMap().get(rankTempMsg.getTeamId());
                    if (teamData == null) {
                        continue;
                    }
                    for (Map.Entry<Long, Long> longEntry : teamData.getMemberList().entrySet()) {
                        long uid = longEntry.getKey();
                        DouLuoDaLuUserData user = activity.getAllUserMap().get(uid);
                        if (user != null) {
                            addUserRankData(msg, teamConditionType, uid, i);
                        }
                    }
                    i++;
                }
            } else {
                CrossDouLuoDaLuMgr.getLogger().info("DouLuoDaLuCrossRank activity : {} groupId {} not in memory", activityId, groupId);
            }
        }
        return msg;
    }
}
